﻿using System;
using CSharp.Basic.Learn.EventBus;
namespace CSharp.Basic.Learn.发布订阅.委托实现
{
    /// <summary>
    /// 钓鱼竿 (被观察者)
    /// refs: https://www.jianshu.com/p/45675c73296d
    /// </summary>v
    public class FishingBod
    {
        // 声明委托
        public delegate void FishingHandler(FishingEventData eventData);
        // 声明事件
        public event FishingHandler FishingEvent;

        public void Fishing()
        {
            Console.WriteLine("开始垂钓了");
            //用随机数模拟鱼咬钩，若随机数为偶数，则为鱼咬钩
            if (new Random().Next() % 2 == 0)
            {
                var a = new Random(10).Next();
                //var type = (FishType)new Random().Next(0, 5);
                var eventSource = new FishingEventData
                {
                    FishType = (FishType)new Random().Next(0, 5)
                };
                Console.WriteLine("铃铛：叮叮叮，鱼儿咬钩了");
                FishingEvent?.Invoke(eventSource);
            }
        }
    }
}
